package com.dxk.shrioConfig;


import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.LinkedHashMap;
import java.util.Map;

@Configuration
public class shrioConfig {

    //shiroFactoryBean "3
    @Bean
    public ShiroFilterFactoryBean getShiroFilterFactoryBean(@Qualifier("getDefaultWebSecurityManager") DefaultWebSecurityManager manager){
        ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
        //设置安全管理器
        bean.setSecurityManager(manager);
        Map<String,String> map = new LinkedHashMap<>();
        map.put("/view/add","authc");
        map.put("/view/update","authc");

        bean.setFilterChainDefinitionMap(map);

        bean.setLoginUrl("/tologin");
        return bean;

    }

    //defaultWebSecurity :2
    @Bean
    public DefaultWebSecurityManager getDefaultWebSecurityManager(@Qualifier("getUserRealm") UserRealm realm){

        DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
        manager.setRealm(realm);
        return manager;
    }
    //创建 realm对象  //需要自定义类 UserRealm  :1
    @Bean
    public UserRealm getUserRealm(){

    return new UserRealm();
    }




}
